﻿Imports System.Data.SqlClient
Public Class Groups
    Public Shared Function getGroup() As SortedList
        Dim cmd As New SqlCommand("SELECT * FROM  [GROUP]", Dbinterface.Connection)

        Dim reader As SqlDataReader = cmd.ExecuteReader
        Dim list As New SortedList
        While reader.Read
            Dim group As New GroupInfo
            With group
                .GroupId = reader("GROUP_ID").ToString
                .GroupName = reader("GROUP_NAME").ToString
                .Active = reader("ACTIVE").ToString

                list.Add(group.GroupId, group)

            End With
        End While
        reader.Close()
        reader = Nothing
        cmd = Nothing
        Return list

    End Function
    Public Shared Function GetDepartment() As DataTable


        Try


            Dim dataAdapter As SqlDataAdapter
            dataAdapter = New SqlDataAdapter("SELECT * FROM [GROUP] WHERE ACTIVE=1", CType(Dbinterface.Connection, SqlConnection))
            Dim dataTable As DataTable = New DataTable()
            dataAdapter.Fill(dataTable)
            Return dataTable
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
            Return Nothing
        End Try
    End Function
    Public Shared Sub UpdateDepartment(ByVal gp As GroupInfo)


        CmdPro.Begin()

        Try


            CmdPro.Parameters("@id") = gp.GroupId
            CmdPro.Parameters("@groupName") = gp.GroupName
            CmdPro.Parameters("@active") = gp.Active
            gp.GroupId = CmdPro.ExecuteNonQuery("UpdateGroup")
            CmdPro.Commit()


        Catch ex As Exception


            CmdPro.Rollback()


            MsgBox(ex.Message)


        End Try


    End Sub

    Public Shared Sub AddDepartment(ByVal gp As GroupInfo)


        CmdPro.Begin()

        Try



            CmdPro.Parameters("@groupName") = gp.GroupName
            CmdPro.Parameters("@active") = gp.Active
            gp.GroupId = CmdPro.ExecuteNonQuery("InsertGroup", "@id")
            CmdPro.Commit()


        Catch ex As Exception


            CmdPro.Rollback()


            MsgBox(ex.Message)


        End Try


    End Sub


End Class
